<script setup lang="tsx">
import { useTable } from '@/hooks/common/table';
import { $t } from '@/locales';
import { fetchAllAreaTree } from '@/service/api';
import { useAppStore } from '@/store/modules/app';
import AreaSearch from './modules/area-search.vue';

const appStore = useAppStore();

const { columns, data, loading, mobilePagination, getDataByPage, searchParams, resetSearchParams } = useTable({
  apiFn: fetchAllAreaTree,
  showTotal: true,
  apiParams: {
    current: 1,
    size: 10,
    id: null
  },
  columns: () => [
    {
      type: 'selection'
    },
    {
      key: 'id',
      title: $t('page.manage.area.id'),
      align: 'center',
      width: 100
    },
    {
      key: 'name',
      title: $t('page.manage.area.name'),
      align: 'center',
      width: 500,
      ellipsis: {
        tooltip: true
      }
    }
  ]
});
</script>

<template>
  <div class="flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
    <AreaSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />

    <NCard :title="$t('page.manage.area.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
      <NDataTable
        :columns="columns"
        :data="data"
        size="small"
        :flex-height="!appStore.isMobile"
        :scroll-x="2088"
        :loading="loading"
        :row-key="row => row.id"
        remote
        :pagination="mobilePagination"
        class="sm:h-full"
      />

      <!-- <LogLoginDetailModel v-model:visible="modelVisible" :row-data="editingData" /> -->
    </NCard>
  </div>
</template>

<style scoped></style>
